package com.hd.pzhwlxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hd.pzhwlxt.mapper.StaffBasicInfoMapper;
import com.hd.pzhwlxt.pojo.Department;
import com.hd.pzhwlxt.pojo.StaffBasicInfo;
import com.hd.pzhwlxt.service.DepartmentService;
import com.hd.pzhwlxt.service.StaffBasicInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @create: 2022-09-20 14:28
 * @author: 怀念天空
 * @Description:
 */

@Service
public class StaffBasicInfoServiceImpl extends ServiceImpl<StaffBasicInfoMapper, StaffBasicInfo> implements StaffBasicInfoService {

    @Autowired
    private StaffBasicInfoMapper staffBasicInfoMapper;


    @Autowired
    private DepartmentService departmentService;

    @Override
    public Page<StaffBasicInfo> getAllStaffInfoPage(Integer pageNum,Integer pageSize) {
        return staffBasicInfoMapper.getAllStaffInfoPage(new Page<>(pageNum,pageSize));
    }

    @Override
    public List<StaffBasicInfo> getAllStaffInfo() {
        return staffBasicInfoMapper.getAllStaffInfo();
    }

    @Override
    public List<StaffBasicInfo> getStaffByDepart() {
        Department dept = departmentService.getDeptByName("维修部");
        QueryWrapper<StaffBasicInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("department_id", dept.getDeptId());
        return staffBasicInfoMapper.selectList(wrapper);
    }

    @Override
    public List<StaffBasicInfo> getStaffByDepartAndPower(String depart, Integer power) {
        return staffBasicInfoMapper.getStaffByDepartAndPower(depart,power);
    }

    @Override
    public StaffBasicInfo login(StaffBasicInfo staffBasicInfo) {
        QueryWrapper<StaffBasicInfo> adminQueryWrapper = new QueryWrapper<>();
        adminQueryWrapper.eq("staff_name",staffBasicInfo.getStaffName());
        adminQueryWrapper.eq("power",1);
//        String enteredPassword = MD5Util.getMD5(staffBasicInfo.getPassword());
        adminQueryWrapper.eq("password",staffBasicInfo.getPassword());
        StaffBasicInfo one = getOne(adminQueryWrapper);
        return one;
    }
}
